package ct.zxd.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ct.zxd.db.Dao;

public class LoginCheck extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request,response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String logName=request.getParameter("logName");
        String password= request.getParameter("password");
        log(logName);
        
        try {
            Dao dao=new Dao();
            String passwd;  
            
        	passwd=dao.loginCheck(logName);
        	if(passwd==null){
        		request.setAttribute("err", "当前用户不存在");
        		request.getRequestDispatcher("Login.jsp").forward(request, response); 
        		return;
        	}
        	if(!passwd.equals(password)){
        		request.setAttribute("err", "密码错误");
        		request.getRequestDispatcher("Login.jsp").forward(request, response); 
        		return;
        	}
        	
        	//�����ַ������
        	request.setAttribute("shopid", logName);
			request.getRequestDispatcher("index.jsp").forward(request, response);   
		 
		} catch (SQLException e) {
			
			// TODO Auto-generated catch block
			throw new ServletException("数据库操作异常,请与数据库管理员联系!");
		} catch (NumberFormatException e){
			request.setAttribute("err", "当前用户不存在");
    		request.getRequestDispatcher("Login.jsp").forward(request, response);
		}
        
		
	}

}
